package Day17;

import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main1 {
    public static int n , m;
    public static int[] dx = {0,0,1,-1,1,1,-1,-1};
    public static int[] dy = {1,-1,0,0,-1,1,-1,1};
    public static int[][] dp;
    public static int[][] arr;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        n = scan.nextInt();
        m = scan.nextInt();
        arr = new int[n + 1][m + 1];
        for(int i = 1; i < n + 1; i++){
          for(int j = 1; j < m + 1; j++){
            arr[i][j] = scan.nextInt();
          }
        }

        dp = new int[n + 2][m + 2];
        for(int i = 1; i < n + 1; i ++){
          for(int j = 1; j < m + 1; j++){
            if(arr[i][j] == 1){
              dp[i][j] = 9;
            }else{
              dp[i][j] = dfs(i,j);
            }
            System.out.print(dp[i][j] + " ");
          }
          System.out.println();
        }
        scan.close();
    }

    public static int dfs(int i , int j){
      for(int k = 0; k < 8; k++){
        int a = dx[k] + i , b = dy[k] + j;
        if(a >= 0 && a < n + 1 && b >= 0 && b < m + 1 && arr[a][b] == 1){
          dp[i][j]++;
        }
      }
      return dp[i][j];
    }
}